<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: #000;
        }

        .box {
            position: relative;
            width: 360px;
            height: 30px;
            line-height: 30px;
            margin: 100px auto;
            background-color: #fff;
        }

        span {
            position: absolute;
            top: 0;
            left: 0;
            width: 50px;
            height: 30px;
            background: url(images/yun.png) no-repeat center;
        }

        ul {
            padding: 0;
            margin: 0;
        }

        li {
            float: left;
            list-style: none;
            margin-left: 20px;
        }
    </style>
    <script src="js/animate.js"></script>

</head>

<body>
    <div class="box">
        <span class="icon"></span>
        <ul>
            <li>首页</li>
            <li>列表</li>
            <li>商业</li>
            <li>下页</li>
            <li>结束</li>
        </ul>
    </div>
    <script>

        var icon = document.querySelector('.icon');
        var ul = document.querySelector('ul');
        var lis = ul.querySelectorAll('li');
        //给所有的小li绑定事件
        var current = 0;
        var flag = true;
        for (var i = 0; i < lis.length; i++) {
            lis[i].addEventListener('mouseenter', function () {
                if (flag) {
                    flag = false;
                    animate(icon, this.offsetLeft, function () {
                        flag = true;
                    });
                }
            });
            lis[i].addEventListener('mouseleave', function () {
                if (flag) {
                    flag = false;
                    animate(icon, current, function () {
                        flag = true;
                    });
                }
            });
            lis[i].addEventListener('click', function () {
                if (flag) {
                    flag = false;
                    current = this.offsetLeft;
                    flag = true;
                }
            });
        }
    </script>
</body>

</html>